package pl.smath.web.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.DataResource;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant;

public class MathTheoryWidget extends Composite {

	private Anchor anchor;
	private HTML html = new HTML();
	
	public MathTheoryWidget(String resourceName){
		if (resourceName == "uproszczenia"){
			anchor = new Anchor("pomoc");
			initWidget(anchor);
			anchor.setStylePrimaryName("math_theory_anchor");
			html.setStylePrimaryName("math_theory_html");
			
			anchor.addClickHandler(new ClickHandler() {
				
				@Override
				public void onClick(ClickEvent event) {
					html.setHTML(Resources.INSTANCE.uproszczenia().getText());
					DecoratedPopupPanel simplePopup = new DecoratedPopupPanel(true);
					int delta = 400 - anchor.getOffsetWidth();
					simplePopup.setWidth("400px");
				    simplePopup.setWidget(html);
		            int left = anchor.getAbsoluteLeft() - delta;
		            int top = anchor.getAbsoluteTop() + 18;
		            simplePopup.setPopupPosition(left, top);
		            simplePopup.show();
		            refreshMathSymbols();
				}
			});
		}
	}
	
	/**
	 * Odswiezenie wzorow matematycznych na stronie
	 */
	public static native void refreshMathSymbols() /*-{
	  $wnd.jsMath.ProcessBeforeShowing();
	}-*/;
}
